package com.morehair.controller.wx;

import com.morehair.bean.pojo.Address;
import com.morehair.bean.vo.admin.AdDataVO;
import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.bean.vo.wx.WxAddressVo;
import com.morehair.service.wx.WxAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * Author  kkw
 * Date  2021/6/8 19:03
 * Version 1.0
 * Description :
 */
@RestController
@RequestMapping("wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService addressService;

    @GetMapping("list")
    public BaseRespVo getAddress() {
        List<WxAddressVo> addressVoList=addressService.getAddress();
        return BaseRespVo.ok(addressVoList);
    }

    @PostMapping("delete")
    public BaseRespVo deleteAddress(@RequestBody Map<String,Integer> map) {
        Integer id = map.get("id");
        addressService.deleteAddressById(id);
        return BaseRespVo.ok();
    }

    @GetMapping("detail")
    public BaseRespVo getDetail(Integer id) {
        Address address=addressService.getAddressDetailById(id);
        return BaseRespVo.ok(address);
    }

    @PostMapping("save")
    public BaseRespVo saveAddress(@RequestBody Address address) {
        addressService.updateAddress(address);
        return BaseRespVo.ok(address.getId());
    }


}
